var express = require('express');
var router = express.Router();
var { familyModel, userModel, admissRegisterModel, addCaregiverModel,copyModel,familyModel} = require("../model/model");


router.post('/getFamily', async (req, res) => {
    let data = await familyModel.find().populate("userid").populate("relationid")
    res.send({
        code: 200,
        data: data
    })
})
//添加入院信息
router.post('/addAdmiss', async (req, res) => {
    let body = req.body
    await admissRegisterModel.create(body)
    res.send({
        code: 200,
        msg: "添加入院信息成功"
    })
})


//查找数据
router.post('/getStatus', async (req, res) => {
    let { username } = req.body
    console.log(username)
    let data = await admissRegisterModel.find({ username })
    res.send({
        code: 200,
        data
    })
})

router.post('/addCaregiver', async (req, res) => {
    let body = req.body
    await addCaregiverModel.create(body)
    res.send({
        code: 200,
        msg: "添加成功"
    })
})

router.post('/getCaregiver', async (req, res) => {
    let data = await addCaregiverModel.find()
    res.send({
        code: 200,
        data
    })
})

router.post('/getItem',async(req,res)=>{
    let {_id}=req.body
    let item=await addCaregiverModel.findOne({_id})
    res.send({
        code:200,
        data:item
    })
})

router.post('/addCopy',async(req,res)=>{
    let body=req.body
    await copyModel.create(body)
    res.send({
        code:200
    })
})

router.post('/getCopy',async(req,res)=>{
    let data=await copyModel.find()
    res.send({
        code:200,
        data
    })
})

router.post('/getOrderDetail',async(req,res)=>{
    let {_id}=req.body
    let data=await copyModel.findOne({_id})
    res.send({
        code:200,
        data
    })
})

router.post('/changeStatus',async(req,res)=>{
    let {_id}=req.body
    await copyModel.updateOne({_id},{$set:{status:0}})
    res.send({
        code:200
    })
})

router.post('/getDate11',async(req,res)=>{
    let data=await copyModel.find()
    res.send({
        code:200,
        data
    })
})
module.exports = router;
